package com.codedef.controller;

import com.codedef.common.response.Result;
import com.codedef.service.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Slf4j
@RestController
public class LoginController {

    @Autowired
    LoginService loginService;


    @GetMapping("/test")
    public String test() {
        System.out.println("123test");
        return "曹操bu";
    }

    @GetMapping("/test2")
    public Result test2() {
        return Result.SUCCESS();
    }

    @GetMapping("/dbtime")
    public String testDbTime() {
        return loginService.testDbTime();
    }

    @RequestMapping(path = "/login", method = {RequestMethod.GET, RequestMethod.POST})
    public Result login(@RequestBody Map<String, String> reqMap) {
        log.info(reqMap.toString());
        String sign = loginService.userLogin(reqMap.get("username"), reqMap.get(reqMap.get("password")));
        if (sign == null) {
            log.error("===== 用户签名失败 =====");
            return Result.FAIL().setMessage("登录失败");
        }

        System.out.println(Result.SUCCESS(sign));
        return Result.SUCCESS(sign);

    }


}
